package com.ruibang.glass.produce.controller.system;


import com.ruibang.glass.produce.entity.MonitorPoint;
import com.ruibang.glass.produce.service.MonitorPointService;
import com.teaming.cloud.framework2.common.model.ResultBody;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;



/**
 * @author 宋锦康
 */
@Api(tags = "监测点信息接口")
@RestController
@RequestMapping("/api/glass/produce/monitorPoint")
public class MonitorPointController {

    @Autowired
    private MonitorPointService monitorPointService;


    @GetMapping("/{id}")
    @ApiOperation(value = "根据ID获取详情", response = ResultBody.class)
    public ResultBody<MonitorPoint> get(@PathVariable String id) {
        return ResultBody.success(monitorPointService.getById(id));
    }

    @PostMapping("/add")
    @ApiOperation(value = "新增实体", response = ResultBody.class)
    public ResultBody add(@RequestBody @ApiParam("实体信息") MonitorPoint entity) {
        monitorPointService.save(entity);
        return ResultBody.success();
    }

    @PostMapping("/batchAdd")
    @ApiOperation(value = "批量新增实体", response = ResultBody.class)
    public ResultBody batchAdd(@RequestBody @ApiParam("实体信息") List<MonitorPoint> entityList) {
        monitorPointService.saveBatch(entityList);
        return ResultBody.success();
    }

    @PutMapping("/edit")
    @ApiOperation(value = "修改实体", response = ResultBody.class)
    public ResultBody update(@RequestBody MonitorPoint entity) {
        monitorPointService.updateById(entity);
        return ResultBody.success();
    }

    @DeleteMapping("/{id}")
    @ApiOperation(value = "删除实体", response = ResultBody.class)
    public ResultBody delete(@PathVariable @ApiParam("主键ID") String id) {
        monitorPointService.removeById(id);
        return ResultBody.success();
    }

    @PostMapping("/delete")
    @ApiOperation(value = "批量删除实体", response = ResultBody.class)
    public ResultBody delete(@RequestBody @ApiParam("主键ID") List<Object> ids) {
        monitorPointService.removeByIds(ids);
        return ResultBody.success();
    }

    @GetMapping("/queryDataByDeviceId/{deviceId}")
    @ApiOperation(value = "监测点信息", response = ResultBody.class)
    public ResultBody<List<MonitorPoint>> queryDataByDeviceId(@PathVariable String deviceId) {
        return ResultBody.success(monitorPointService.queryMonitorPoints(deviceId));
    }

    @PostMapping("/updateOrderNum")
    @ApiOperation(value = "更新排序码", response = ResultBody.class)
    public ResultBody updateOrderNum(@RequestParam String monitorId, @RequestParam Integer orderNum) {
        monitorPointService.updateOrderNum(monitorId, orderNum);
        return ResultBody.success();
    }

    @ApiOperation(value = "根据设备ids和获取监测点信息", response = ResultBody.class)
    @PostMapping("/getMonitorByDeviceId")
    public ResultBody getMonitorByDeviceId(@RequestBody List<String> deviceIds) {
        return ResultBody.success(monitorPointService.getMonitorPointByDeviceId(deviceIds));
    }
}
